import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;



public class Student {
	private int id;
	private String name;
	private int age;
	private double grade;

	public Student() {

	}

	public Student(int id, String name, int age, double grade) {
		this.id = id;
		this.setName(name);
		this.setAge(age);
		this.setGrade(grade);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (name.length() > 10) {
			throw new IllegalArgumentException("name's length should <=10 " + name.length());
		}
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		if (age <= 0) {
			throw new IllegalArgumentException("age should >0 " + age);
		}
		this.age = age;
	}

	public double getGrade() {
		return grade;
	}

	public void setGrade(double grade) {
		if (grade < 0 || grade > 100) {
			throw new IllegalArgumentException("grade should be in [0,100] " + grade);
		}
		this.grade = grade;
	}

	public static void main(String[] args) throws Exception {
		Student[] students = new Student[3];
		students[0] = new Student(100, "Carl", 18, 80);
		students[1] = new Student(101, "Jaker", 19, 90);
		students[2] = new Student(102, "Tom", 20, 85);

		PrintWriter ar = null;
		BufferedReader br = null;
		try {
			FileWriter fw = new FileWriter("d:/student.txt");
			ar = new PrintWriter(fw);
			writeData(students, ar);
			ar.close();

			
			FileReader fr = new FileReader("d:/student.txt");
			br = new BufferedReader(fr);
			String line = null;
			while ((line = br.readLine()) != null)
				System.out.println(line);
			

		} catch (IOException exception) {
			exception.printStackTrace();
		}finally{
			if (br != null) {
				br.close();
			}
		}
	}

	private static void writeData(Student[] students, PrintWriter ar) throws IOException {
		for (Student e : students)
			e.writeData(ar);
	}

	public void writeData(PrintWriter out) {

		out.println(id + "|" + name + "|" + age + "|" + grade);
	}

}
